#include <iostream>
#include <deque>
using namespace std;

int lastRemaining(int n, int m)
{
	std::deque<int>  rec;
	for(int i=0;i<n;++i){
		rec.push_back(i);
	}
	int count=1;
	while(rec.size() != 1){
		int temp=rec.front();
		rec.pop_front();
		if(count != m){
			rec.push_back(temp);
		}else{
			count=1;
		}
	}
}

int main(int argc, char* argv[])
{

    return 0;
}
